<template>
  <div class="sidebar" v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(50, 65, 87, 0.8)">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="sidebar.collapse" background-color="#324157" text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <WMenu :items="items"></WMenu>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed } from "vue";
import { useRoute } from "vue-router";
import WMenu from "@/components/homeView/MenuView.vue";
import { useSidebarStore } from "@/store/sidebar";
import { useMenuStore } from "@/store/menu";
import type { IMenu } from "@/types/menu";

const route = useRoute();
const loading = ref(false);
let items = reactive<Array<IMenu>>([]);
const sidebar = useSidebarStore();
const menuStore = useMenuStore();
items = menuStore.menuList;

const onRoutes = computed(() => {
  return route.path.replace("/", "");
});
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}

.sidebar > ul {
  min-height: 100%;
}
</style>
